package com.service.supply;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.excel.EasyExcel;
import com.common.StringUtils;
import com.common.easyui.EasyuiUtils;
import com.common.http.HttpResult;
import com.common.model.Global;
import com.common.spring.SpringMvcUtils;
import com.dao.purchase.BillGoodDao;
import com.model.purchase.BillGoodModel;
import com.model.supply.SupplyUserModel;
import com.model.sys.SysUser;

@Service("supplyBillGoodService")
public class BillGoodService {
	static final Logger logger = LoggerFactory.getLogger(BillGoodService.class);

	@Autowired
	BillGoodDao billGoodDao;

	/**
	 * 列表查询
	 *
	 * @param queryMap
	 * @return
	 */
	public HttpResult selectList(Map<String, Object> queryMap) {
		HttpResult httpResult = new HttpResult();
		EasyuiUtils.addPageNum(queryMap);
		EasyuiUtils.addFilter(queryMap);
		SupplyUserModel supplyUserModel = SpringMvcUtils.getSupplyUser();
//		queryMap.put("infCode", supplyUserModel.getInfId());
		List<BillGoodModel> list = billGoodDao.selectList(queryMap);
		int count = billGoodDao.selectListCount(queryMap);
		httpResult.setRows(list);
		httpResult.setTotal(count);
		logger.info("selectList:{}", list);
		return httpResult;
	}

	public void export(Map<String, Object> queryMap, HttpServletResponse response) {
	
		List<BillGoodModel> list = billGoodDao.selectList(queryMap);
		logger.info("export:{}", list);
		try {
			EasyExcel.write(response.getOutputStream(), BillGoodModel.class).sheet("模板").doWrite(list);
		} catch (IOException e) {
			logger.error("导出错误:{}", e.getMessage());
		}

	}
}
